// pages/mine/mine.js
const app=getApp()
const utils = require('../../utils/util')
const db = wx.cloud.database()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    userInfo:null,
    userInfo:null
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    console.log(app.globalData.userInfo);
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  onShareAppMessage(){},
  onShareTimeline(){},
  onAddToFavorites(){},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
          this.setData({ 
              userInfo: app.globalData.userInfo
           })
  },


  showMana(){
    this.selectComponent(".password").show()
  },
  clickPersonal(){
    if(app.globalData.userInfo==null){
      wx.showToast({
        title: '请先登录',
        icon:'none',
        duration:2000
      })
    }else{
      wx.navigateTo({
        url: '../../otherTap/pages/personal/personal',
      }) 
    }
  },
  clickSnapshot(){
    wx.navigateTo({
      url: '../../otherTap/pages/snapshotCheck/snapshotCheck',
    })
  },
  clickSetup(){
    wx.navigateTo({
      url: '../../otherTap/pages/setUp/setUp',
    })
  },
  clickMysnapshots(){
    wx.navigateTo({
      url: '../../otherTap/pages/MySnapshots/Mysnapshots',
    })
  },
    Login(){
        if(app.globalData.userInfo==null){
      utils.login().then(()=>{
              this.setData({ 
                userInfo: app.globalData.userInfo
             })
            }).catch(()=>{})
    }
      },
  logOut(){
    wx.showModal({
      title: '提示',
      content: '确定要退出吗？',
      success: (res)=> {
        if (res.confirm) {
          db.collection("login_user").where({
            _openid:app.globalData.openid
          }).remove({
            success:(res)=>{
              console.log(res)
            }
          })
          app.globalData.userInfo=null,
          
          this.setData({
            userInfo:null,
          })
        } else {
        }
      }
    })
  },
  telephone(){
    wx.navigateTo({
      url: '../../otherTap/pages/telephone/telephone',
    })
  },
  clickCollection(){
    wx.navigateTo({
      url: '../../otherTap/pages/Mycollection/Mycollection',
    })
  },

})